package com.hdjk.view.callback;

import com.hdjk.view.entity.TotalAssetsEntity;
import com.lst.projectlib.entity.Msg;

import org.json.JSONObject;

import java.math.BigDecimal;

import okhttp3.Response;

/**
 * Created by sxy on 2017/11/2.
 */

public abstract class GetTotalAssetsCallBack extends MsgCallBack {
    @Override
    public Msg parseNetworkResponse(Response response, int i) throws Exception {
        Msg msg = super.parseNetworkResponse(response, i);
        JSONObject object = (JSONObject) msg.getData();
        if (object!=null) {
            TotalAssetsEntity entity = new TotalAssetsEntity();
            if (!object.isNull("accumulatedProfitLoss")) {
                double l = object.getDouble("accumulatedProfitLoss");
                BigDecimal b = new BigDecimal(l);
                entity.setAccumulatedProfitLoss(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("currentAmount")) {
                double l = object.getDouble("currentAmount");
                BigDecimal b = new BigDecimal(l);
                entity.setCurrentAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("intransitAssets")) {
                double l = object.getDouble("intransitAssets");
                BigDecimal b = new BigDecimal(l);
                entity.setIntransitAssets(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("investmentAmount")) {
                double l = object.getDouble("investmentAmount");
                BigDecimal b = new BigDecimal(l);
                entity.setInvestmentAmount(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("profitLoss")) {
                double l = object.getDouble("profitLoss");
                BigDecimal b = new BigDecimal(l);
                entity.setProfitLoss(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("profitLossDaily")) {
                double l = object.getDouble("profitLossDaily");
                BigDecimal b = new BigDecimal(l);
                entity.setProfitLossDaily(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("profitLossPercent")) {
                double l = object.getDouble("profitLossPercent");
                BigDecimal b = new BigDecimal(l);
                entity.setProfitLossPercent(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            msg.setData(entity);
        }
        return msg;
    }
}
